package com.example.myspringbootpj.controller;


import com.example.myspringbootpj.mapper.UserMapper;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HeaderController {

    private final UserMapper userMapper;
    @Autowired
    public HeaderController(UserMapper userMapper ) {
        this.userMapper = userMapper;
    }
//获取头像
    @GetMapping("/header")
    public String getHeader(HttpSession session) {
        String USERID = (String) session.getAttribute("userID");

        if (USERID == null) {
            return ("用户未登录！");
        }

        // 打印日志，确认userID的值
        System.out.println("获取的USERID: " + USERID);


//调用mapper获取用户头像信息
        String userImage = userMapper.selectUserImage(USERID);
        return "根据id获取用户头像"+userImage;
    }
}
